package com.wpen.unit.web.controller.system;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wpen.unit.service.system.UserService;
import com.wpen.unit.web.dto.system.ChangePwdRequest;
import com.wpen.unit.web.dto.system.ChangePwdResponse;
import com.wpen.unit.web.dto.system.SysUserAddRequest;
import com.wpen.unit.web.dto.system.SysUserAddResponse;
import com.wpen.unit.web.dto.system.SysUserEnabledRequest;
import com.wpen.unit.web.dto.system.SysUserEnabledResponse;
import com.wpen.unit.web.dto.system.SysUserListRequest;
import com.wpen.unit.web.dto.system.SysUserListResponse;
import com.wpen.unit.web.dto.system.SysUserModRequest;
import com.wpen.unit.web.dto.system.SysUserModResponse;
import com.wpen.unit.web.dto.system.UserInfoRequest;
import com.wpen.unit.web.dto.system.UserInfoResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 
 * @author Administrator
 *
 */
@Tag(name = "基础-用户信息服务接口")
@RestController
@RequestMapping("/api")
public class UserController {
    @Autowired
    private UserService loginUserService;
    @Autowired
    private HttpServletRequest request;

    @Operation(summary = "用户密码-密码修改")
    @PostMapping(value = "/change/pwd", produces = MediaType.APPLICATION_JSON_VALUE)
    public ChangePwdResponse changePwd(@RequestBody @Valid ChangePwdRequest changePwdParam) throws Exception {
        return loginUserService.changePwd(request, changePwdParam);
    }

    @Operation(summary = "个人信息查询")
    @PostMapping(value = "/userInfo", produces = MediaType.APPLICATION_JSON_VALUE)
    public UserInfoResponse userInfo(@RequestBody @Valid UserInfoRequest userInfoParam) throws Exception {
        return loginUserService.queryUserInfo(request, userInfoParam);
    }

    @Operation(summary = "用户新增")
    @PostMapping(value = "/user/add", produces = MediaType.APPLICATION_JSON_VALUE)
    public SysUserAddResponse sysUserAdd(@RequestBody @Valid SysUserAddRequest sysUserAddParam) throws Exception {
        return loginUserService.addSysUser(sysUserAddParam);
    }

    @Operation(summary = "用户修改")
    @PostMapping(value = "/user/mod", produces = MediaType.APPLICATION_JSON_VALUE)
    public SysUserModResponse sysUserMod(@RequestBody @Valid SysUserModRequest sysUserModParam) throws Exception {
        return loginUserService.modSysUser(sysUserModParam);
    }
    
    @Operation(summary = "用户状态修改")
    @PostMapping(value = "/user/enabled", produces = MediaType.APPLICATION_JSON_VALUE)
    public SysUserEnabledResponse sysUserEnabled(@RequestBody @Valid SysUserEnabledRequest sysUserModParam) throws Exception {
        return loginUserService.enabledSysUser(sysUserModParam);
    }

    @Operation(summary = "用户列表查询")
    @PostMapping(value = "/user/list", produces = MediaType.APPLICATION_JSON_VALUE)
    public SysUserListResponse sysUserList(@RequestBody @Valid SysUserListRequest sysUserListParam) throws Exception {
        return loginUserService.queryListSysUser(sysUserListParam);
    }

}
